package com.huike.controller.system;

import com.huike.dto.MenuPageDto;
import com.huike.entity.SysMenu;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/menu")
@Slf4j
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 菜单分页模糊查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public Result<PageResult> menuList(@RequestBody MenuPageDto dto) {
        log.info("菜单分页模糊查询:{}",dto);
        return menuService.list(dto);
    }

    /**
     * 菜单目录回显
     * @return
     */
    @GetMapping("/all")
    public Result all(){
        log.info("目录回显");
        return menuService.all();
    }

    /**
     * 删除菜单
     * @param menuId
     * @return
     */
    @DeleteMapping("/del/{id}")
    public Result deleteById(@PathVariable("id") Long menuId){
        return menuService.deleteById(menuId);
    }

    /**
     * 菜单保存
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public Result saveMenu(@RequestBody SysMenu dto){
        return menuService.saveMenu(dto);
    }

    /**
     * 修改菜单
     * @param dto
     * @return
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody SysMenu dto){
        return menuService.updateById(dto);
    }

}
